<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
</head>

<body>
    <h1>创建axios实例</h1>
    <button>提交</button>


    <script>
        const oBtn = document.querySelector("button")
        const myAxios = axios.create({
            baseURL: "/",
            timeout: 10000,
            headers: {}
        })

        myAxios.interceptors.request.use(config => {
            console.log(config);
            alert("拦截器")
            return config //一定要放行
        }, err => {
            return Promise.reject(err.message)
        })


        oBtn.onclick = async function () {
            const result = await myAxios.get("/user", {
                params: {
                    userId: "001"
                }
            })
            console.log(result.data);
        }
    </script>
</body>

</html>